package Generics;

import java.util.ArrayList;
import java.util.Objects;
import java.util.function.Consumer;

public class GenericsDemo4 {
//    泛型通配符
    public static void main(String[] args) {
        ArrayList<Coder> list1=new ArrayList<>();
        list1.add(new Coder());
        list1.get(0).work();
        ArrayList<Manager> list2=new ArrayList<>();
        list2.add(new Manager());
        list2.get(0).work();

        ArrayList<Mover> list3=new ArrayList<>();
        list3.add(new Mover());
        method(list1);
        method(list2);
        list3.get(0).work();
        method(list3);

    }
//    ArrayList<?>代表任意类型
//    ? extends Employee代表可以传入Employee或者Employee的子类，否则编译会报错
//    ? super Employee代表可以传入Employee或者Employee的父类，否则编译会报错
    public static void method(ArrayList<? extends Employee> list){
        for(Object o:list){
            Employee e=(Employee) o;
            e.work();
        }
    }
}

abstract class Employee{
    private String name;
    private double salary;
    public Employee(){

    }
    public abstract void work();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }
}
class Coder extends Employee{
    @Override
    public void work(){
        System.out.println("写代码");
    }
}
class Manager extends Employee{
    @Override
    public void work(){
        System.out.println("项目经理分配任务");
    }
}
class Mover extends Employee{
    @Override
    public void work(){
        System.out.println("正在理货");
    }
}